import 'dart:async';

import 'package:get/get.dart';

class CountDownDialogLogic extends GetxController {
  Duration duration;

  Timer? timer;
  CountDownDialogLogic(this.duration);
  RxInt countDown = 0.obs;
  @override
  void onInit() {
    super.onInit();
    countDown.value = duration.inSeconds;
    timer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
      if (countDown.value > 0) {
        countDown.value--;
      } else {
        timer.cancel();
        Get.back(result: true);
      }
    });
  }

  @override
  void onClose() {
    super.onClose();
    timer?.cancel();
  }
}
